package com.dc.base.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class RequestInfoUtil {
	
	/**
	 * 获取请求的地址
	 * @author 沈煌江
	 * @return
	 */
	public static String getController() {
		return Thread.currentThread().getStackTrace()[2].getMethodName();
	}
	
	/**
	 * 获取请求的参数
	 * @author 沈煌江
	 * @param request
	 * @return
	 */
	public static String getParmMap(HttpServletRequest request) {
		Map<String, String[]> map = request.getParameterMap();
		Map<String, String> result = new HashMap<String, String>();
		Iterator<Map.Entry<String, String[]>> iterator = map.entrySet()
				.iterator();
		while (iterator.hasNext()) {
			Map.Entry<String, String[]> entry = iterator.next();
			result.put(entry.getKey(), LString2String(entry.getValue(), "-"));

		}
		return result.toString();
	}
	
	private static String LString2String(String[] lstr, String split) {
		StringBuffer sb = new StringBuffer();
		for (String string : lstr) {
			sb.append(string).append(split);
		}
		return sb.substring(0, sb.length() - 1);
	}
	
}
